﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBUtils;

public partial class Salary_PrintSalary : System.Web.UI.Page
{
    DataSet dsResult;
    /// <summary>
    /// 网页初始化时执行该方法。设置控件属性
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //绑定年份列表
            for (int year = DateTime.Today.Year; year >= 2003; year--)
            {
                ListItem item = new ListItem(year.ToString(), year.ToString());
                DropDownList1.Items.Add(item);
            }
        }
    }

    /// <summary>
    /// 当用户单击“确定”按钮时，该方法将显示指定月份的工资信息。
    /// 该过程调用 SalaryInfo.QueryHistorySalary(CInt(Session("EmployeeID")), strStartDate, strEndDate, dsResult) 函数，在数据库中搜索该员工该月的工资信息。
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        dsResult = new DataSet();

        DateTime dateStart = new DateTime(Convert.ToInt32(DropDownList1.SelectedValue), Convert.ToInt32(DropDownList2.SelectedValue), 1).AddDays(-1);
        DateTime dateEnd = dateStart.AddDays(1).AddMonths(1);


        if (SalaryInfo.QueryHistorySalary(Convert.ToInt32(Session["EmployeeID"]), dateStart.ToString(), dateEnd.ToString(), ref dsResult) == 1)
        {
            if (dsResult.Tables[0].Rows.Count == 0)
            {
                Label3.Visible = true;
            }
            grdResult.DataSource = dsResult.Tables[0];
            grdResult.DataBind();
            grdResult.Visible = true;
        }
        else
        {
            this.Response.Write("<script>alert('" + "查询信息失败" + "');</script>");//弹出失败信息
        }
    }

    /// <summary>
    /// 当用户单击“打印工资单”按钮时，该方法打开一个新的浏览器窗口，显示工资单的具体内容。
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnPrint_Click(object sender, EventArgs e)
    {
        Employee emp = new Employee();
        Employee.GetEmployeeInfo(Convert.ToInt32(Session["EmployeeID"]), emp);



        this.Response.Write("<script>window.open('Print.aspx?name=" + emp.Name + "&dept=" + emp.DeptName + "&month=" + Convert.ToDateTime(grdResult.SelectedRow.Cells[0].Text).Month.ToString() + "&basic=" + grdResult.SelectedRow.Cells[1].Text + "&overtime=" + grdResult.SelectedRow.Cells[2].Text + "&absenct=" + grdResult.SelectedRow.Cells[3].Text + "&other=" + grdResult.SelectedRow.Cells[4].Text + "&actural=" + grdResult.SelectedRow.Cells[5].Text + "')</script>");
    }
    protected void grdResult_SelectedIndexChanged(object sender, EventArgs e)
    {
        btnPrint.Visible = true;
    }
}
